package com.algorithm.ch1.cjm.heap;

/**
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/9/18
 * @Version 1.0
 */
public class OutOfMemoryError {

    public static void main(String[] args) {

        long[] arr;
        for (int i=1; i<=10000000; i*=2) {

            System.out.println("size :" + i);

            arr = new long[i];

            Runtime runtime = Runtime.getRuntime();

            System.out.printf("maxMemory : %.2fM\n", runtime.maxMemory()*1.0/1024/1024);
            System.out.printf("totalMemory : %.2fM\n", runtime.totalMemory()*1.0/1024/1024);
            System.out.printf("freeMemory : %.2fM\n", runtime.freeMemory()*1.0/1024/1024);
            
        }

    }
}
